<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>用户表单</title>
    <link rel="stylesheet" th:href="@{/css/style.css}">
</head>
<body>
    <div class="container">
        <h1 th:text="${user.id == null ? '新建用户' : '编辑用户'}">用户表单</h1>
        
        <form th:action="@{/users}" th:object="${user}" method="post">
            <input type="hidden" th:field="*{id}" />
            
            <div class="form-group">
                <label>用户名：</label>
                <input type="text" th:field="*{name}" class="form-control" />
                <div class="error" th:if="${#fields.hasErrors('name')}" 
                     th:errors="*{name}"></div>
            </div>
            
            <div class="form-group">
                <label>邮箱：</label>
                <input type="email" th:field="*{email}" class="form-control" />
                <div class="error" th:if="${#fields.hasErrors('email')}" 
                     th:errors="*{email}"></div>
            </div>

            <div class="form-group">
                <label>手机号：</label>
                <input type="tel" th:field="*{phone}" class="form-control" />
                <div class="error" th:if="${#fields.hasErrors('phone')}" 
                     th:errors="*{phone}"></div>
            </div>

            <div class="form-group">
                <label>性别：</label>
                <select th:field="*{gender}" class="form-control">
                    <option value="">请选择性别</option>
                    <option th:each="gender : ${T(com.example.demo.model.User.Gender).values()}"
                            th:value="${gender}"
                            th:text="${gender.displayName}">
                    </option>
                </select>
                <div class="error" th:if="${#fields.hasErrors('gender')}" 
                     th:errors="*{gender}"></div>
            </div>

            <div class="form-group">
                <label>出生日期：</label>
                <input type="date" th:field="*{birthDate}" class="form-control" />
                <div class="error" th:if="${#fields.hasErrors('birthDate')}" 
                     th:errors="*{birthDate}"></div>
            </div>

            <div class="form-group">
                <label>地址：</label>
                <input type="text" th:field="*{address}" class="form-control" />
                <div class="error" th:if="${#fields.hasErrors('address')}" 
                     th:errors="*{address}"></div>
            </div>

            <div class="form-group">
                <label>个人简介：</label>
                <textarea th:field="*{bio}" class="form-control" rows="3"></textarea>
                <div class="error" th:if="${#fields.hasErrors('bio')}" 
                     th:errors="*{bio}"></div>
            </div>
            
            <div class="form-group">
                <button type="submit" class="btn btn-primary">保存</button>
                <a th:href="@{/users}" class="btn btn-secondary">返回</a>
            </div>
        </form>
    </div>
</body>
</html> 